package com.kedacom.demo.modularity.core;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * 业务异常实体类，用于在http传输时序列化（json）所用<br />
 * BusinessException之所以不能用于http传输，是因为其Throwable类型的cause参数无法序列化
 * @author luocanfeng
 * @date 2013-8-23
 */
@XmlRootElement(name = "businessException")
public class BusinessExceptionEntity implements Serializable {

	/** serialVersionUID */
	private static final long serialVersionUID = -388149070382437098L;

	private String code;
	private String message;

	// private String trace;

	public BusinessExceptionEntity() {
	}

	public BusinessExceptionEntity(String message) {
		super();
		this.message = message;
	}

	public BusinessExceptionEntity(String code, String message) {
		super();
		this.code = code;
		this.message = message;
	}

	public BusinessException toBusinessException() {
		return new BusinessException(this.code, this.message);
	}

	public static BusinessExceptionEntity fromBusinessException(BusinessException exception) {
		return new BusinessExceptionEntity(exception.getCode(), exception.getMessage());
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
